package com.scoresystem.web.service;

import java.util.ArrayList;
import java.util.List;

import com.scoresystem.common.CommonValue;
import com.scoresystem.dao.DaoFactory;
import com.scoresystem.dao.IRemarkDao;
import com.scoresystem.dao.IScoreDao;
import com.scoresystem.json.JsonContext;
import com.scoresystem.json.JsonState;
import com.scoresystem.model.Score;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

/**
 * 用于实现学生查看成绩，提交反馈的业务逻辑
 * @author Administrator
 *
 */
public class StudentService {
	private DaoFactory factory=DaoFactory.getInstance();
	//维护json的状态类
	private JsonState state=new JsonState();
	//根据不同的json状态选择不同的处理方法
	private JsonContext context=new JsonContext(state);
	public JSONObject checkoutScores(String stunum){
		IScoreDao dao=factory.createScoreDao();
		List<Score> list=null;
		try{
			list=dao.listscores(stunum);
			if(list==null){
				state.setState(CommonValue.STATE_FAILED);
				return context.getObject("查询失败", null, null);
			}
			else{
				JSONArray jsonArr = JSONArray.fromObject(list);
				state.setState(CommonValue.STATE_SUCCESS);
				return context.getObject("查询成功", null, jsonArr);
			}
		}
		catch(Exception e){
			e.printStackTrace();
		}
		return new JSONObject();
	}
	
	public JSONObject checkoutRemark(String stunum,String worknum,String remark){
		IRemarkDao dao=factory.createRemarkDao();
		try{
			if(dao.modify(stunum, worknum, remark)){
				state.setState(CommonValue.STATE_SUCCESS);
				return context.getObject("修改成功", null, null);
			}
			else{
				state.setState(CommonValue.STATE_FAILED);
				return context.getObject("修改失败", null, null);
			}
		}
		catch(Exception e){
			e.printStackTrace();
		}
		return new JSONObject();
	}
	
	
}
